Setting Attribute Default Value

Hi,

I am planning to copy an existing populated module to another folder (in the same database) to use it as a template for a new module, because I want all the same attributes, as well as the object layout etc.

When I copy the module, I want to go thru and reset all the attributes to their Default Values, as the value will be different for the new module.

Does anyone have a simple DXL script that I can run that will got thru each attribute and reset it to the default value, or is there another way of doing this?

Thanks

Mark


Skaifey05 - Wed Jun 05 02:06:50 EDT 2013

Re: Setting Attribute Default Value
Johnny_P - Wed Jun 05 04:33:20 EDT 2013

Hi,

that depends on how many attributes you want to reset. If there are just a few attributes, the quickest way would be via the object properties window. In the Attributes tab you can select an attribute, assign a value and apply to "Objects in current view" or "Selected objects".

 

Some time ago I wrote a little script to reset attribute values for selected attributes.

  1. Make sure, that you have no filter applied if you want to reset the attribute for ALL objects (The script asks you if you want to apply the default values only for values in the current view if you have a filter applied)
  2. Select the attributes you want to reset
  3. Click "Reset values" and "Continue" if you are sure, that you have selected the correct attributes.

So if you have a lot of attributes you can try it:

Module m = current
AttrDef ad = null
string sDummy[] = {}
DB dbAttr = null
DBE dbeListViewAttributes = null
DBE dbeButtonSelectAll = null
DBE dbeButtonDeselectAll = null
int iIndex = 0

// select all checkboxes
void selectAll(DBE dbe)
{
    int i = null
    int iNoElems = noElems(dbeListViewAttributes)
    
    for (i=0; i<iNoElems; i++)
    {
        setCheck(dbeListViewAttributes, i, true)
    }
}

// deselect all checkboxes
void deselectAll(DBE dbe)
{
    int i = null
    int iNoElems = noElems(dbeListViewAttributes)
    
    for (i=0; i<iNoElems; i++)
    {
        setCheck(dbeListViewAttributes, i, false)
    }
}

// reset selected attribute values
void resetValues(DB db)
{
    int i = null
    int iNoElems = noElems(dbeListViewAttributes)
    int iAttrCounter = 0
    Object o = null
    string sCurAttribute = null
    Skip skpAttributesToReset = createString()
    bool bCancel = false
    
    for (i=0; i<iNoElems; i++)
    {
        if (getCheck(dbeListViewAttributes, i))
        {
            sCurAttribute = getColumnValue(dbeListViewAttributes, i, 0)
            put(skpAttributesToReset, sCurAttribute, sCurAttribute)
            iAttrCounter++
        }
    }

    string sChoices[] = { "Continue", "Cancel" }
    int iContinue = query("You are about to reset the values for all selected attributes (" iAttrCounter "):\n\nDo you want to continue?", sChoices)
    
    // continue
    if (iContinue == 0)
    {
        // check if a filter is applied
        if (filtering(m))
        {    
            string sChoicesFilter[] = { "Continue with applied filter", "Disable filter and continue", "Cancel" }
            int iMode = query("There is a filter applied.\nDo you want to continue and reset only attribute values for objects in the current view or do you want to disable the filter?", sChoicesFilter)
            
            if (iMode == 0) {} // continue
            elseif (iMode == 1)
            {
                filtering off
            }
            elseif (iMode == 2)
            {
                bCancel = true
            }
        }
        
        if (!bCancel)
        {
            // loop through all objects in the view and reset all selected attribute values
            for o in m do
            {
                for sCurAttribute in skpAttributesToReset do
                {
                    o.sCurAttribute = ""
                }
            }
        }
    }
    elseif (iContinue == 1)
    {
        bCancel = true
    }
    
    
    refresh m
    delete skpAttributesToReset
    
    if (!bCancel)
    {
        destroy db
        infoBox "done"
    }
}

dbAttr = create("Reset attribute values", styleCentered)
dbeListViewAttributes = listView(dbAttr, listViewOptionCheckboxes, 300, 10, sDummy)
dbeButtonSelectAll = button(dbAttr, "Select all", selectAll)
beside dbAttr
dbeButtonDeselectAll = button(dbAttr, "Deselect all", deselectAll)
apply(dbAttr, "Reset values", resetValues)

realize dbAttr
insertColumn(dbeListViewAttributes, 0, "Attributes", 250, iconNone)
setExtraHeightShare(dbeListViewAttributes, 1.0)

// list all available attributes in the listview
for ad in m do
{
    if (!ad.object || ad.system) { continue } // skip module only attributes and systems attributes
    insert(dbeListViewAttributes, iIndex++, ad.name)
}

show dbAttr

Regards Johnny

 

Re: Setting Attribute Default Value
Mike.Scharnow - Wed Jun 05 10:00:20 EDT 2013

Johnny_P - Wed Jun 05 04:33:20 EDT 2013

Hi,

that depends on how many attributes you want to reset. If there are just a few attributes, the quickest way would be via the object properties window. In the Attributes tab you can select an attribute, assign a value and apply to "Objects in current view" or "Selected objects".

 

Some time ago I wrote a little script to reset attribute values for selected attributes.

  1. Make sure, that you have no filter applied if you want to reset the attribute for ALL objects (The script asks you if you want to apply the default values only for values in the current view if you have a filter applied)
  2. Select the attributes you want to reset
  3. Click "Reset values" and "Continue" if you are sure, that you have selected the correct attributes.

So if you have a lot of attributes you can try it:

Module m = current
AttrDef ad = null
string sDummy[] = {}
DB dbAttr = null
DBE dbeListViewAttributes = null
DBE dbeButtonSelectAll = null
DBE dbeButtonDeselectAll = null
int iIndex = 0

// select all checkboxes
void selectAll(DBE dbe)
{
    int i = null
    int iNoElems = noElems(dbeListViewAttributes)
    
    for (i=0; i<iNoElems; i++)
    {
        setCheck(dbeListViewAttributes, i, true)
    }
}

// deselect all checkboxes
void deselectAll(DBE dbe)
{
    int i = null
    int iNoElems = noElems(dbeListViewAttributes)
    
    for (i=0; i<iNoElems; i++)
    {
        setCheck(dbeListViewAttributes, i, false)
    }
}

// reset selected attribute values
void resetValues(DB db)
{
    int i = null
    int iNoElems = noElems(dbeListViewAttributes)
    int iAttrCounter = 0
    Object o = null
    string sCurAttribute = null
    Skip skpAttributesToReset = createString()
    bool bCancel = false
    
    for (i=0; i<iNoElems; i++)
    {
        if (getCheck(dbeListViewAttributes, i))
        {
            sCurAttribute = getColumnValue(dbeListViewAttributes, i, 0)
            put(skpAttributesToReset, sCurAttribute, sCurAttribute)
            iAttrCounter++
        }
    }

    string sChoices[] = { "Continue", "Cancel" }
    int iContinue = query("You are about to reset the values for all selected attributes (" iAttrCounter "):\n\nDo you want to continue?", sChoices)
    
    // continue
    if (iContinue == 0)
    {
        // check if a filter is applied
        if (filtering(m))
        {    
            string sChoicesFilter[] = { "Continue with applied filter", "Disable filter and continue", "Cancel" }
            int iMode = query("There is a filter applied.\nDo you want to continue and reset only attribute values for objects in the current view or do you want to disable the filter?", sChoicesFilter)
            
            if (iMode == 0) {} // continue
            elseif (iMode == 1)
            {
                filtering off
            }
            elseif (iMode == 2)
            {
                bCancel = true
            }
        }
        
        if (!bCancel)
        {
            // loop through all objects in the view and reset all selected attribute values
            for o in m do
            {
                for sCurAttribute in skpAttributesToReset do
                {
                    o.sCurAttribute = ""
                }
            }
        }
    }
    elseif (iContinue == 1)
    {
        bCancel = true
    }
    
    
    refresh m
    delete skpAttributesToReset
    
    if (!bCancel)
    {
        destroy db
        infoBox "done"
    }
}

dbAttr = create("Reset attribute values", styleCentered)
dbeListViewAttributes = listView(dbAttr, listViewOptionCheckboxes, 300, 10, sDummy)
dbeButtonSelectAll = button(dbAttr, "Select all", selectAll)
beside dbAttr
dbeButtonDeselectAll = button(dbAttr, "Deselect all", deselectAll)
apply(dbAttr, "Reset values", resetValues)

realize dbAttr
insertColumn(dbeListViewAttributes, 0, "Attributes", 250, iconNone)
setExtraHeightShare(dbeListViewAttributes, 1.0)

// list all available attributes in the listview
for ad in m do
{
    if (!ad.object || ad.system) { continue } // skip module only attributes and systems attributes
    insert(dbeListViewAttributes, iIndex++, ad.name)
}

show dbAttr

Regards Johnny

 

Hello Johnny,

on an unrelated side note: how did you manage to write this code block?

Is there a tag like the old "{ code }"?

 

BR
Mike

Re: Setting Attribute Default Value
llandale - Wed Jun 05 13:14:15 EDT 2013

If you set an obj-attr-value to null it will appear to have the default value.

  • for o in entire m do {o."MyCustomAttr" = ""}

-Louie

Re: Setting Attribute Default Value
Skaifey05 - Wed Jun 05 18:06:13 EDT 2013

Hi Johnny an Louie,

Thanks for the responses, both are very helpful. Once I actually get started I will see which option works the best. It may be that I end up using the option that works best on the particular module.

Cheers

Mark

Re: Setting Attribute Default Value
Pekka_Makinen - Thu Jun 06 00:31:00 EDT 2013

Mike.Scharnow - Wed Jun 05 10:00:20 EDT 2013

Hello Johnny,

on an unrelated side note: how did you manage to write this code block?

Is there a tag like the old "{ code }"?

 

BR
Mike

The grey area is a blockquote - you can select it from the editor window by using the button with large "-character.

Seems to do the work for displaying DXL code examples.